package com.lyl.controller;

import com.lyl.model.Result;
import com.lyl.model.WebLog;
import com.lyl.service.TestService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.crypto.Data;
import java.util.Date;

/**
 * @author lylbell
 * @date 2021-06-21 17:03
 */
@RestController
@Api(tags = "coin-common模块的测试")
public class TestController {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Autowired
    private TestService testService;

    /**
     * 测试日志和swagger
     * */
    @GetMapping("/test/common")
    @ApiOperation(value = "coin-common的测试方法",authorizations = @Authorization("token"))
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param", value = "参数1", dataType = "String", paramType = "query", example = "param1"),
            @ApiImplicitParam(name = "param2", value = "参数2", dataType = "String", paramType = "query", example = "param2")
    })
    public Result<String> testCommon(String param,String param2) {
        return Result.ok("测试成功",param + "," + param2);
    }

    /**
     * 测试时间
     * @return
     */
    @GetMapping("/test/date")
    @ApiOperation(value = "测试时间",authorizations = @Authorization("token"))
    public Result<Date> testDate() {
        return Result.ok(new Date());
    }

    /**
     * 测试redis
     * @return
     */
    @GetMapping("/test/redis")
    @ApiOperation(value = "redis测试",authorizations = @Authorization("token"))
    public Result<String> testRedis() {
        WebLog webLog = new WebLog();
        webLog.setUsername("lyl-redis-test");
        webLog.setResult("测试redis");
        redisTemplate.opsForValue().set("com.lyl.controller.testRedis",webLog);
        return Result.ok("redis测试成功");
    }

    /***
     * 测试jetchche
     * @param username
     * @return
     */
    @GetMapping("/test/jetcache")
    @ApiOperation(value = "jetcache缓存的测试",authorizations = {@Authorization("token")})
    public Result<String> testJetCache(String username){
        WebLog webLog = testService.get(username);
        System.out.println(webLog);
        return Result.ok("OK") ;
    }
}
